/**
* Copyright 2009, Jethro Grassie, Creative Jar Technology Ltd (http://www.cjtech.co.uk)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
**/

package com.adobe.cairngorm.business;

import com.adobe.cairngorm.business.RMITask;

abstract public class RMIService extends AbstractService
{
    protected function invoke(callInfo:RMICallInfo):Void
    {
        var listener:RMIListener = RMIListener
        {
            override function onResult(data:Object):Void
            {
                if(responders.size() > 0)
                {
                    var lastResponder:Responder = responders.get(responders.size()-1) as Responder;
                    lastResponder.onResult(data);
                    responders.remove(lastResponder);
                }
            }
            override function onFault(data:Object):Void
            {
                if(responders.size() > 0)
                {
                    var lastResponder:Responder = responders.get(responders.size()-1) as Responder;
                    lastResponder.onFault(data);
                    responders.remove(lastResponder);
                }
            }
        };
        var task:RMITask = RMITask
        {
            listener: listener;
            callInfo: callInfo;
        };
        task.start();
    }
}

